﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="BOM.aspx.cs" Inherits="Main_Inventory_BOM" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="AjaxControl" %>
<%@ Register Src="~/User Controls/PageHeading.ascx" TagName="heading" TagPrefix="acc" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Bill of Material</title>
    <link rel="Stylesheet" href="../../Styles/accounts.css" type="text/css" />        
</head>

<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" EnablePartialRendering="true" EnablePageMethods="true" runat="server"> </asp:ScriptManager>
     
          <div class="divmain" > <acc:heading ID="pagehead" runat="server" HeadingText="Bill of Material" /> </div>    
                 <div style="width:90%; margin-left:5%; margin-right:5%;">        
                    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                        <ContentTemplate>
                         <div style="margin-left:5%; margin-right:5%; width:90%" align="center"><asp:Label ID="lblMsg" runat="server" Font-Bold="true"></asp:Label></div> 
                                <asp:UpdateProgress DynamicLayout="false" ID="UpdProgress" runat="server">
                                    <ProgressTemplate> <div align="center"><img src="../../Images/ajax-loader.gif" /></div> </ProgressTemplate>
                                </asp:UpdateProgress>
                                  
                                  <asp:HiddenField ID="HidControl" runat="server" /> 
                                
                                    <table class="tablecontent"  style= "width:85%; margin-left:5%; border:1px solid #818181" >
                                          <tr>
                                                <td class="headtd" colspan="6"> 
                                                   Items Details
                                                   
                                               </td>
                                               
                                          </tr>
                                         
                                         <tr>
                                                <td  style="width:40%">Item <span style="color:Red">*</span>&nbsp; </td>
                                                <td colspan="5" style="width:60%"> <asp:DropDownList ID="DDLItem" runat="server" 
                                                        onselectedindexchanged="DDLItem_SelectedIndexChanged" AutoPostBack="true"> </asp:DropDownList></td>
                                         </tr>
                                         
                                         <tr>
                                                <td style="width:20%">Quantity <span style="color:Red">*</span>&nbsp;  </td>
                                                <td style="width:20%"> <asp:TextBox ID="TxtQuantity" runat="server" Text="0.00" CssClass ="inputnumber" onKeyPress= "return isNumberKey(this.id,event)"> </asp:TextBox> </td>
                                                <td style="width:20%"> Unit Symbol</td>
                                                <td style="width:20%"> <asp:TextBox ID="TxtUnitSymbol" CssClass="input" ReadOnly="true" runat="server"> </asp:TextBox></td>
                                                <td style="width:10%">Active </td>
                                                <td style="width:10%"> <asp:CheckBox ID="ChkActive" runat="server" /></td>
                                         </tr>
                                         
                                          <tr>
                                                <td> Remarks </td>
                                                <td colspan="5"> <asp:TextBox ID="TxtRemarks" MaxLength="100" Width="140px" TextMode="MultiLine" runat="server"> </asp:TextBox> </td> 
                                         </tr>
                                         
                                         <tr>
                                                <td> Edit in Transaction</td>
                                                <td colspan="5"> <asp:CheckBox ID="ChkEditTransaction" runat="server" /></td>
                                         </tr>
                                         
                                   </table>
                                   
                                   <table id="tblItem" runat="server" style="width:85%; margin-left:5%; margin-top:10px;" class="tablecontent" cellpadding="2" cellspacing="0">
                                        <tr>
                                            <td style ="border-right:1px solid #818181; border-bottom:1px solid #818181; text-align:center; font-weight:bold">Item Name</td>
                                            <td style ="border-right:1px solid #818181; border-bottom:1px solid #818181; text-align:center; font-weight:bold">Unit</td>
                                            <td style ="border-right:1px solid #818181; border-bottom:1px solid #818181; text-align:center; font-weight:bold">Quantity</td>
                                        </tr>
                                        
                                        <tr>
                                            <td style="width:19%; vertical-align:top"> 
                                                <asp:DropDownList  id="DDLItemName1" runat="server" width="99%" 
                                                    CssClass="dropdown"  AutoPostBack="True" onchange="return checkItemRepetion(this.id)" 
                                                    onselectedindexchanged="DropDown_SelectedIndexChanged" ></asp:DropDownList>                                                
                                            </td>
                                            
                                            <td style="width:14%; vertical-align:top">                            
                                                <asp:Textbox id="TxtUnit1" runat="server" width="99%" ReadOnly="true" CssClass="input"  ></asp:Textbox>                                                
                                            </td>
                                            
                                            <td style="width:8%; vertical-align:top">
                                                <asp:TextBox ID="TxtQty1" runat="server" CssClass="inputnumber" Width="99%" Text="0.00" onKeyPress="return isNumberKey(this.id,event)" AutoCompleteType="Disabled" ></asp:TextBox>                            
                                            </td>
                                            
                                        </tr>
                                        
                                        <tr>
                                            <td style="width:19%; vertical-align:top"> 
                                                <asp:DropDownList  id="DDLItemName2" runat="server" width="99%" 
                                                    CssClass="dropdown"  AutoPostBack="True"  onchange="return checkItemRepetion(this.id)"
                                                    onselectedindexchanged="DropDown_SelectedIndexChanged" ></asp:DropDownList>                                                
                                            </td>
                                            
                                            <td style="width:14%; vertical-align:top">                            
                                                 <asp:Textbox  id="TxtUnit2" runat="server" width="99%" CssClass="input" ReadOnly="true" ></asp:TextBox>                                                
                                            </td>
                                            
                                            <td style="width:8%; vertical-align:top">
                                                <asp:TextBox ID="TxtQty2" runat="server" CssClass="inputnumber" Width="99%" Text="0.00" onKeyPress="return isNumberKey(this.id,event)" AutoCompleteType="Disabled" ></asp:TextBox>                            
                                            </td>
                                            
                                        </tr>
                                        
                                         <tr>
                                            <td style="width:19%; vertical-align:top"> 
                                                <asp:DropDownList  id="DDLItemName3" runat="server" width="99%" 
                                                    CssClass="dropdown"  AutoPostBack="True"  onchange="return checkItemRepetion(this.id)"
                                                    onselectedindexchanged="DropDown_SelectedIndexChanged" ></asp:DropDownList>                                                
                                            </td>
                                            
                                            <td style="width:14%; vertical-align:top">                            
                                                 <asp:Textbox  id="TxtUnit3" runat="server" CssClass="input" width="99%" ReadOnly="true"   ></asp:Textbox>                                                
                                            </td>
                                            
                                            <td style="width:8%; vertical-align:top">
                                                <asp:TextBox ID="TxtQty3" runat="server" CssClass="inputnumber" Width="99%" Text="0.00" onKeyPress="return isNumberKey(this.id,event)" AutoCompleteType="Disabled" ></asp:TextBox>                            
                                            </td>
                                            
                                        </tr>
                                        
                                         <tr>
                                            <td style="width:19%; vertical-align:top"> 
                                                <asp:DropDownList  id="DDLItemName4" runat="server" width="99%" 
                                                    CssClass="dropdown"  AutoPostBack="True"  onchange="return checkItemRepetion(this.id)"
                                                    onselectedindexchanged="DropDown_SelectedIndexChanged" ></asp:DropDownList>                                                
                                            </td>
                                            
                                            <td style="width:14%; vertical-align:top">                            
                                                 <asp:Textbox  id="TxtUnit4" runat="server" CssClass="input" width="99%" ReadOnly="true" ></asp:Textbox>                                                
                                            </td>
                                            
                                            <td style="width:8%; vertical-align:top">
                                                <asp:TextBox ID="TxtQty4" runat="server" CssClass="inputnumber" Width="99%" Text="0.00" onKeyPress="return isNumberKey(this.id,event)" AutoCompleteType="Disabled" ></asp:TextBox>                            
                                            </td>
                                            
                                        </tr>
                                        
                                        
                                        <tr>
                                            <td style="width:19%; vertical-align:top"> 
                                                <asp:DropDownList  id="DDLItemName5" runat="server" width="99%" 
                                                    CssClass="dropdown"  AutoPostBack="True"  onchange="return checkItemRepetion(this.id)"
                                                    onselectedindexchanged="DropDown_SelectedIndexChanged" ></asp:DropDownList>                                                
                                            </td>
                                            
                                            <td style="width:14%; vertical-align:top">                            
                                                 <asp:Textbox  id="TxtUnit5" runat="server" CssClass="input" width="99%" ReadOnly="true" ></asp:Textbox>                                                
                                            </td>
                                            
                                            <td style="width:8%; vertical-align:top">
                                                <asp:TextBox ID="TxtQty5" runat="server" CssClass="inputnumber" Width="99%" Text="0.00" onKeyPress="return isNumberKey(this.id,event)" AutoCompleteType="Disabled" ></asp:TextBox>                            
                                            </td>
                                            
                                        </tr>
                                        
                                        
                               </table>
                                                    
                              <table style="width: 95%; margin-top: 10px;" align="right">
                                    <tr>
                                        <td >
                                            <asp:LinkButton ID="btnAddMore" runat="server" OnClick="btnAddMore_Click"
                                               CausesValidation="false" > 
                                                <img src="../../Images/More.jpg" alt="Add New Row" />
                                            </asp:LinkButton>
                                        </td>
                                    </tr>
                             </table>
                                
                                <table style="width:85%; margin-left:5%; margin-top: 5%;">
                                        <tr>
                                            <td style="width:19%;" align="right" >  
                                                    <asp:Button ID="BtnSave" runat="server" CssClass="button" Text="Save"  onclick="BtnSave_Click" OnClientClick="return ValidateItems();" />
                                                    
                                            </td>
                                            <td style="width:14%;" align="left" >&nbsp; <asp:Button ID="BtnClose" 
                                                    runat="server" CssClass="button" Text="Close" onclick="BtnClose_Click" /> </td>
                                            <td style="width:8%;"> &nbsp;</td>
                                        </tr>
                                </table>
                        </ContentTemplate>
                     </asp:UpdatePanel>
          </div>
    </form>

      <script src="../../JavaScript/Commons.js" type="text/javascript"></script>
      <script language="javascript" type="text/javascript">
          function ValidateItems() {

              //var flag=new Boolean(true);
              if (document.getElementById("DDLItem").selectedIndex == '0') {
                  alert('Please Select Item Name ');
                  document.getElementById("DDLItem").focus();
                  return false;
              }

              else if (document.getElementById("TxtQuantity").value == '' || parseFloat(document.getElementById("TxtQuantity").value) == 0) {
                  alert('Please Enter Valid Quantity');
                  document.getElementById("TxtQuantity").focus();
                  return false;
              }

              else if (document.getElementById("DDLItemName1").selectedIndex == '0') {
                  alert('Please Select First Item ');
                  document.getElementById("DDLItemName1").focus();
                  return false;

              }
              else if (document.getElementById("TxtQty1").value == '' || parseFloat(document.getElementById("TxtQty1").value) == 0) {
                  alert('Please Enter Valid Quantity');
                  document.getElementById("TxtQty1").focus();
                  return false;
              }
              else if (!validatecontrols()) {
                  alert('Please Enter Valid Quantity');
                  return false;
              }
              else {
                  return true;
              }

          }

          function validatecontrols() {
              var count = document.getElementById("HidControl").value;
              var isvalid = new Boolean(true);

              for (var i = 1; i <= count; i++) {
                  if (document.getElementById("DDLItemName" + i).selectedIndex != '0') {
                      if (document.getElementById("TxtQty" + i).value == '' || parseFloat(document.getElementById("TxtQty" + i).value) == 0) {

                          isvalid = false;
                          break;

                      }
                  }
              }
              return isvalid;
          }

          function checkItemRepetion(id) {
              //function to prevent duplicate item selection
              var flag = new Boolean(true);
              var ddl = document.getElementById(id);
              var currentValue = ddl.options[ddl.selectedIndex].value;
              var Count = document.getElementById("HidControl").value;
              for (var i = 1; i <= Count; i++) {
                  var previous = document.getElementById("DDLItemName" + i);
                  var previousValue = previous.options[previous.selectedIndex].value;
                  if (ddl.value == '0') {
                      document.getElementById("TxtUnit" + i).value = '';
                      flag = false;
                  }
                  else if (ddl != previous) {
                      if (currentValue == previousValue) {
                          alert('Please Select Unique Item');
                          ddl.selectedIndex = 0;
                          flag = false;
                          break;
                      }
                  }
              }
              if (flag == true) {                                       //use only when your
                  setTimeout('__doPostBack(\'' + id + '\',\'\')', 0);       // dropdown has autopostback as true.
              }                                                             // otherwise leave this line commented.
              return flag;
          }
   </script>
</body>
</html>
